﻿using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Text;

namespace nwrole.lib
{
    public class ConsoleLogWriter : TextWriter
    {
        /*public ConsoleLogWriter(IPluginDebug debug)
        {
            this.debug = debug;
        }*/

        /*public override void Write(char value)
        {
            base.Write(value);
            _output.AppendText(value.ToString()); // When character data is written, append it to the text box.
        }*/

        /*public override void  Write(char[] buffer)
        {
            File.AppendAllText(@"c:\temp\testlog.txt", new string(buffer));
 	        base.Write(buffer);
        }*/

        private Object logLock = new Object();

        public override void Write(char[] buffer, int index, int count)
        {
            lock (logLock)
            {
                try
                {
                    File.AppendAllText(@"c:\temp\testlog.txt", new string(buffer));
                }
                catch{}
                
            }
            base.Write(buffer, index, count);
        }

        public override Encoding Encoding
        {
            get { return System.Text.Encoding.UTF8; }
        }
    }
}
